export class Tool {
    static objectUrlEncode(obj) {
        let string = "?"
        if (!obj) return '';
        for (let key in obj) {
            string += '&' + key + '=' + obj[key]
        }
        return string.replace('&', '')
    }

    static objectToJSON(obj) {
        return JSON.parse(JSON.stringify(obj || {}))
    }

    static clone(def, name, config) {
        if (!def[name]) def[name] = {};
        switch(name) {
            case 'data':
                if (!config.body) config.body = {};
                Object.keys(def.data || {}).forEach((k) => {
                    if (!config.body[k]) config.body[k] = def.data[k]
                })
            break;
            case 'params':
                if (!config.urlParams) config.urlParams = {};
                Object.keys(def.params || {}).forEach((k) => {
                    if (!config.urlParams[k]) config.urlParams[k] = def.params[k]
                })
            break;
            case 'headers':
                if (!config.headers) config.headers = {};
                Object.keys(def.headers || {}).forEach((k) => {
                    if (!config.headers[k]) config.headers[k] = def.headers[k]
                })
            break;
        }
        
    }
}
Tool.repeatTipMessage = '请不要重复提交!'